package com.pl.itsense.gwt.clientzone.ui;


import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;
import com.pl.itsense.gwt.clientzone.client.ClientZoneServiceAsync;
import com.pl.itsense.gwt.clientzone.client.Clientzone;
import com.pl.itsense.gwt.clientzone.model.MemberDTO;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler; 
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.LinkItem;
import com.smartgwt.client.widgets.form.fields.PasswordItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.form.validator.MatchesFieldValidator;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

public class ChangePasswordPanel extends Window{
	static ChangePasswordPanel instance = null;
	DynamicForm form = new DynamicForm();
	PasswordItem password = new PasswordItem();  
	PasswordItem repassword = new PasswordItem();
	PasswordItem oldPassword = new PasswordItem();  
	MatchesFieldValidator matchesValidator = new MatchesFieldValidator();

	IButton okButton = new IButton("Zmień hasło");
	IButton cancelButton = new IButton("Anuluj");
	
	public ChangePasswordPanel() {
		instance = this;
		init();
	}
	
	
	private void init(){
		setWidth(350);  
		setHeight(180);
		setShowCloseButton(false);
		setTitle("Zmiana hasła - ITSense Sterfa Klienta");  
		setShowMinimizeButton(false);
		setIsModal(true);  
		setShowModalMask(true);  
		centerInPage();  
		setCanDragReposition(false);

		oldPassword.setName("password");
		oldPassword.setTitle("Stare hasło");  
		oldPassword.setRequired(true);  

		password.setName("password");
		password.setTitle("Nowe hasło");  
		password.setRequired(true);  

		
		repassword.setName("repassword");
		repassword.setTitle("Powtórz hasło");  
		repassword.setRequired(true);  
		repassword.setWrapTitle(false);

		matchesValidator.setOtherField("password");  
		matchesValidator.setErrorMessage("Hasła nie pasują");          
		repassword.setValidators(matchesValidator);  

		form.setFields(oldPassword,password,repassword);
	
		okButton.addClickHandler(new ClickHandler() {  
			public void onClick(ClickEvent event) {
				if (form.validate()){
					
					
				}
			}
		});
		
		cancelButton.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				instance.destroy();
				instance = null;
			}
		});

		form.setTop(20);
		form.setLeft(40);
		
		VLayout vLayout = new VLayout();
		vLayout.addChild(form);
		
		
		HLayout hLayout = new HLayout();
		hLayout.setHeight(30);
		hLayout.addMember(okButton);
		hLayout.addMember(cancelButton);		
		hLayout.setTop(120);
		hLayout.setLeft(65);
		hLayout.setMembersMargin(5);  
		vLayout.addChild(hLayout);
		
		addItem(vLayout);
		
	
	}
	
}
